package com.itheima.health.service.impl;

import com.alibaba.dubbo.config.annotation.Service;
import com.itheima.health.constant.MessageConstant;
import com.itheima.health.dao.OrderDao;
import com.itheima.health.entity.Result;
import com.itheima.health.pojo.Order;
import com.itheima.health.service.OrderService;
import com.itheima.health.utils.DateUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.transaction.annotation.Transactional;

import java.util.Map;

/**
 * @author zhengjd
 * @date 2020/4/8 11:19
 */
@Transactional
@Service
public class OrderServiceImpl implements OrderService {

    @Autowired
    OrderDao orderDao;



    /**
     * 添加预约信息
     * @param map
     * @param memberId
     */
    @Override
    public Result add(Map map, Integer memberId) throws Exception {

            Order order = new Order();
            order.setMemberId(memberId);
            order.setOrderDate(DateUtils.parseString2Date((String) map.get("orderDate")));
            order.setOrderType(Order.ORDERTYPE_WEIXIN);
            order.setOrderStatus(Order.ORDERSTATUS_NO);
            order.setSetmealId(Integer.parseInt((String) map.get("setmealId")));
            orderDao.add(order);
            return new Result(true, MessageConstant.ORDER_SUCCESS,order);

    }

    /**
     * 根据id查询预约信息
     * @param id
     * @return
     */
    @Override
    public Map findById(Integer id) {
        return orderDao.findById(id);
    }

    @Override
    public Boolean findByCondition(Order order) {
        int count = orderDao.findByCondition(order);
        return count > 0;
    }
}
